Hey there.
In this lecture, we're going to be making a simple leaderboard that displays the kills, deaths, and
money for every single player in our game.
So let's get started.
We can create a new script inside of the server script service, and I'm going to call this script my
leaderboard handler.
We're going to fill this in with the same comet template as before.
And in order to set up a leaderboard for every single player, we're going to have to get the player
service.
And then we can go ahead and listen for when a player joins our game.
Get that player.
And here we can go ahead and set up a leaderboard forum.
So we'll create a new folder that'll be instance dot new folder.
And then the name of this folder will be our leader stats.
And then we can go ahead and set the parent of the folder equal to our player.
And then we want to create three different int values to represent the kills, deaths and how much money
our player has.
So we can go ahead and create a dedicated function for that.
And we'll call this create int value.
And we can pass the name for the int value.
Um what value we would like to set in it by default as well as the parent for the int value.
And inside of here we'll create a new variable I'll call it int and that's equal to instance dot new.
Create a new int value instance.
And then the name is going to be equal to the name pass to the function the value equal to the value,
and then the parent equal to the parent.
Then we can go ahead and call this function and create, for example, our kill's value.
We'll start off with a default value of zero.
And then the parent is going to be our leader stats folder.
And then we can basically just copy this and do it two more times.
But this time we want to have a value for our players deaths as well as for our players money.
Now we're going to be filling in money and kills later when we add zombies to our game and we set up
the shop for our game.
But we can go ahead and implement the functionality for listening to a player's deaths.
So when a player joins our game, what we can go ahead and do is we can listen for when a player has
their character added to them.
We'll connect a function, get that character.
And then when that character dies.
So character.
And we'll get the humanoid and listen to its died event.
The one we can go ahead and do is refer to the player, access their leader stats folder and inside
of their leader stats folder.
We can get deaths and then we can set the value plus equal to one.
And just like that, we've already set up a basic leaderboard for all the players in our game and it
should increment when our player dies.
So let's go ahead and test that out.
So we can hop into our game.
There's our leaderboard for kills, deaths and money.
And then if I go ahead and reset my character, as you can see, deaths incremented by one and then
it'll stay there on my leaderboard, I can go spawn in my game again and I'll go and reset again.
And as you can see, it increments to two.
So now that we have our leaderboard complete and the next lecture, we're going to take a look at how
to save some of the data in our leaderboard into a data store so we can grab that data when a player
joins our game in a future session.
See you there.